//
//  LZTStatusBottomView.swift
//  LZTWeibo
//
//  Created by Yin jianxun on 16/8/13.
//  Copyright © 2016年 YinJianxun. All rights reserved.
//

import UIKit

class LZTStatusBottomView: UIView {
    
    //转发 此时不能直接实例化，因为类的实例化方法还没有实现
    var retweetBtn: UIButton?
    //评论
    var commentBtn: UIButton?
    //赞
    var unlikeBtn: UIButton?
    
    //具体数字设置
    var statusViewModel: LZTStatusViewModel? {
        
        didSet{
            
            retweetBtn?.setTitle(statusViewModel?.repostsCountStr, forState: UIControlState.Normal)
            commentBtn?.setTitle(statusViewModel?.commentsCountStr, forState: UIControlState.Normal)
            unlikeBtn?.setTitle(statusViewModel?.attitudesCountStr, forState: UIControlState.Normal)

        }
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //设置UI
    func setupUI() {
        
        backgroundColor = UIColor.whiteColor()
        
        //添加按钮
        retweetBtn = addChildButtons("timeline_icon_retweet", title: "转发")
        commentBtn = addChildButtons("timeline_icon_comment", title: "评论")
        unlikeBtn = addChildButtons("timeline_icon_unlike", title: "赞")
        
        let line1 = addChileLines()
        let line2 = addChileLines()
        //添加约束
        retweetBtn!.snp_makeConstraints { (make) in
            make.top.leading.bottom.equalTo(self)
            make.width.equalTo(commentBtn!)
        }
        commentBtn!.snp_makeConstraints { (make) in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetBtn!.snp_trailing)
            make.width.equalTo(unlikeBtn!)
        }
        unlikeBtn!.snp_makeConstraints { (make) in
            make.top.trailing.bottom.equalTo(self)
            make.leading.equalTo(commentBtn!.snp_trailing)
        }
        line1.snp_makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.centerX.equalTo(retweetBtn!.snp_trailing)
        }
        line2.snp_makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.centerX.equalTo(commentBtn!.snp_trailing)
        }
        
    }
    
    func addChildButtons(imgName: String, title: String)-> UIButton {
        
        let button = UIButton()
        //背景图片
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        //设置Image
        button.setImage(UIImage(named:imgName), forState: UIControlState.Normal)
        button.setTitle(title, forState: UIControlState.Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        
        //直接添加button
        addSubview(button)
        return button
    }
    
    func addChileLines() -> UIImageView{
        let img = UIImageView(imgName: "timeline_card_bottom_line")
        addSubview(img)
        return img
    }
    
}
